package com.lmx.messagetemplate.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.textfield.TextInputEditText;
import com.lmx.messagetemplate.R;
import com.lmx.messagetemplate.bean.MessageEvent;
import com.lmx.messagetemplate.bean.MessageTemplate;

import org.apache.commons.lang3.StringUtils;
import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;

public class CreateTemplateActivity extends AppCompatActivity {

    private TextInputEditText etTemplateName;
    private TextInputEditText etTemplate;
    private Button btnNext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_template);
        initView();
        initEvent();
    }

    private void initView() {
        etTemplateName = findViewById(R.id.et_templateName);
        etTemplate = findViewById(R.id.et_template);
        btnNext = findViewById(R.id.btn_next);
    }

    private void initEvent() {
        btnNext.setOnClickListener(v -> {
            String templateName = etTemplateName.getText().toString().trim();
            String template = etTemplate.getText().toString().trim();
            if (StringUtils.isNotBlank(templateName) && StringUtils.isNotBlank(template)) {
                // 创建数据
                MessageTemplate messageTemplate = new MessageTemplate();
                messageTemplate.setTemplateTitle(templateName);
                messageTemplate.setMessageTemplate(template);
                // 传递数据
                Intent intent = new Intent(this, ReplaceContentActivity.class);
                intent.putExtra("template", messageTemplate);
                startActivity(intent);
                finish();
            } else {
                Toast.makeText(this, "模板名称或消息模板不能为空喔！", Toast.LENGTH_SHORT).show();
            }
        });
    }
}